package LeetCode.leetcode491;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Solution {
    public static void main(String[] args) {
        System.out.println(findSubsequences(new int[]{4,6,7,7}));
    }
    /**
     *
     * @param nums 1 <= nums.length <= 15
     *              -100 <= nums[i] <= 100
     * @return
     */
    public static List<List<Integer>> findSubsequences(int[] nums) {
        List<List<Integer>> res = new ArrayList<>();
        List<Integer> path = new ArrayList<>();
        backTracking(path, res, 0,nums);
        return res;
    }

    public static void backTracking(List<Integer> path, List<List<Integer>> res, int startIndex, int[] nums) {
        if (path.size() >= 2) {
            res.add(new ArrayList<>(path));
        }
        if (startIndex == nums.length) {
            return;
        }
        boolean[] used = new boolean[201];
        for (int i = startIndex; i < nums.length; i++) {
            if (!path.isEmpty() && path.get(path.size()-1) > nums[i] ||( used[nums[i]+100])){
                continue;
            }
                used[nums[i]+100] = true;
                path.add(nums[i]);
                backTracking(path,res,i+1,nums);
                path.remove(path.size()-1);
        }
    }
}
